package com.tongfutele.utils;

import com.tongfutele.ProdServiceServiceStub;
import com.tongfutele.bnetv3.*;

import java.rmi.RemoteException;

public class BNetUtils {

    /**
     * 获取 decode 的 MD5 加密结果，统一加密协议
     *
     * @param decode
     * @return String
     * @throws RemoteException
     */
    public static String getEncodeString(String decode) throws RemoteException {
        GetEncodeString getEncodeString = new GetEncodeString();
        getEncodeString.setDecode(decode);
        ProdServiceServiceStub serviceStub = new ProdServiceServiceStub();
        GetEncodeStringResponse response = serviceStub.getEncodeString(getEncodeString);

        return response.getGetEncodeStringReturn();
    }

    /**
     * 依据流水号以及随机令牌取得交易明文
     *
     * @param rand        随机令牌
     * @param Streamingno 流水号
     * @return
     * @throws RemoteException
     */
    public static String getPortalRequest(String rand, String Streamingno) throws RemoteException {
        GetPortalRequest getPortalRequest = new GetPortalRequest();
        getPortalRequest.setRand(rand);
        getPortalRequest.setStreamingno(Streamingno);

        ProdServiceServiceStub serviceStub = new ProdServiceServiceStub();
        GetPortalRequestResponse response = serviceStub.getPortalRequest(getPortalRequest);

        return response.getGetPortalRequestReturn();
    }

    /**
     * 依据XML请求报文取得相应的XML应答报文
     *
     * @param reqXML
     * @return
     * @throws RemoteException
     */
    public static String getPortalResult(String reqXML) throws RemoteException {
        GetPortalResult getPortalResult = new GetPortalResult();
        getPortalResult.setReqXML(reqXML);

        ProdServiceServiceStub serviceStub = new ProdServiceServiceStub();
        GetPortalResultResponse response = serviceStub.getPortalResult(getPortalResult);

        return response.getGetPortalResultReturn();
    }
}
